export const submitMinxins = {
	data() {
		return {}
	},
	methods: {
		//加载数据
		formSubmit() {
			let that = this
			var checkRes = that.$validateCheck.check(that.formData, that.rule)
			if (checkRes) {
				//requestType 请求类型 默认不是put
				if (this.urlapi.requestType === 'put') {
					this.putData(that.formData)
				} else {
					this.postData()
				}
			} else {
				uni.showToast({
					title: that.$validateCheck.error,
					icon: "none"
				});
			}
		},
		postData() {
			let that = this
			uni.$u.http.post(that.urlapi.add, that.formData).then(res => {
				if (that.urlapi.goUtl) {
					that.$u.route({
						type: 'redirect',
						url: that.urlapi.goUtl
					})
				} else {
					uni.showToast({
						title: "post提交成功",
						icon: "none",
					});
				}
			})
		},

		putData() {
			let that = this
			uni.$u.http.put(that.urlapi.add, that.formData).then(res => {
				if (that.urlapi.goUtl) {
					that.$u.route({
						type: 'redirect',
						url: that.urlapi.goUtl
					})
				} else {
					uni.showToast({
						title: "post提交成功",
						icon: "none",
					});

				}
			})
		},

	}
}
export const detailMinxins = {
	data() {
		return {
			detailData:{},//详情数据
		}
	},
	methods: {
		getDetailData(id) {
			let that = this
			let requesUrl = that.urlapi.detail
			if(requesUrl){
				uni.$u.http.get(`${requesUrl}/${id}`).then(res => {
					that.detailData = res
				})
			}
		},

	}
}
export const delMinxins = {
	data() {
		return {
			
		}
	},
	methods: {
		deleteData(id) {
			let that = this
			let requesUrl = that.urlapi.delete
			if(that.urlapi.delete){
				uni.$u.http.delete(`${requesUrl}`,[id]).then(res => {
					uni.showToast({
						title: "删除成功",
						icon: "none",
					});
				})
			}
		},

	}
}
